#pragma once

#include <glm/glm.hpp>
#include <memory>
#include <SDL2/SDL_render.h>
#include <stdexcept>
#include <string>
#include <unordered_map>

namespace engine
{
    namespace resource
    {
        class TextureManager
        {
			friend class ResourceManager;
        public:
            struct SDLTextureDeleter
            {
				void operator()(SDL_Texture* texture) const noexcept
                {
                    if (texture)
                    {
                        SDL_DestroyTexture(texture);
                    }
                }
            };

            TextureManager(SDL_Renderer* renderer);

            TextureManager(const TextureManager&) = delete;
            TextureManager& operator=(const TextureManager&) = delete;
            TextureManager(TextureManager&&) = delete;
			TextureManager& operator=(TextureManager&&) = delete; 

        private:
			SDL_Renderer* m_renderer = nullptr;                            //渲染器
			std::unordered_map<std::string, std::unique_ptr<SDL_Texture, SDLTextureDeleter>> m_textures; //纹理资源

			SDL_Texture* loadTexture(const std::string& filePath); //加载纹理
			SDL_Texture* getTexture(const std::string& filePath);   //获取纹理
			glm::vec2 getTextureSize(const std::string& filePath); //获取纹理尺寸
			void unloadTexture(const std::string& filePath);          //卸载纹理
			void clearTexture();                                                     //清除所有纹理
        };
    }
}
